package com.smalls.newvideotwo.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.smalls.newvideotwo.R;

public class ConfirmDialog extends Dialog {

	private Button mPositiveBtn;
	private Button mNegativeBtn;
	private TextView mCodeText = null;
	private String mCodeString = null;

	public ConfirmDialog(Context activity, int theme,String text) {
		super(activity, theme);
		mCodeString = text;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setCancelable(true);
		setContentView(R.layout.confirm_dialog);

		mCodeText = (TextView)findViewById(R.id.content);
		mPositiveBtn = (Button) findViewById(R.id.setting);
		mNegativeBtn = (Button) findViewById(R.id.exit);
		mPositiveBtn.requestFocus();
		mPositiveBtn.setFocusable(true);
		mPositiveBtn.setOnClickListener(mDefaultBtnLsr);
		mNegativeBtn.setOnClickListener(mDefaultBtnLsr);
		if(mCodeString!=null) {
			mCodeText.setText(mCodeString);
		}
	}

	private DialogButtonListener mPositiveBtnListener;

	public ConfirmDialog setPositiveButtonListener(DialogButtonListener l) {
		mPositiveBtnListener = l;
		return this;
	}

	private DialogButtonListener mNegativeBtnListener;

	public ConfirmDialog setNegativeButtonListener(DialogButtonListener l) {
		mNegativeBtnListener = l;
		return this;
	}

	private View.OnClickListener mDefaultBtnLsr = new View.OnClickListener() {
		public void onClick(View v) {
			if (v.getId() == R.id.setting) {
				if (mPositiveBtnListener != null) {
					mPositiveBtnListener.onClick(ConfirmDialog.this, v);
				} else {
					ConfirmDialog.this.dismiss();
				}
			} else if (v.getId() == R.id.exit) {
				if (mNegativeBtnListener != null) {
					mNegativeBtnListener.onClick(ConfirmDialog.this, v);
				} else {
					ConfirmDialog.this.dismiss();
				}
			}
		}
	};

	public interface DialogButtonListener {
		void onClick(Dialog dlg, View v);
	}

}
